package part15;

/**
 * @author wcj
 * @Date 2021/5/30 15:19
 * @Version 1.0
 */
public class Part1520<T> {

    Class<T> type;

    /**
     * 通过这种方式可以使用isInstance()来匹配泛型
     *
     * @param kind
     */
    public Part1520(Class<T> kind) {
        this.type = kind;
    }

    public boolean f(Object obj) {
        return type.isInstance(obj);
    }

    public static void main(String[] args) {
        Part1520<Building> buildingPart1520 = new Part1520<>(Building.class);
        System.out.println(buildingPart1520.f(new Building()));
        System.out.println(buildingPart1520.f(new House()));
        Part1520<House> housePart1520 = new Part1520<>(House.class);
        System.out.println(housePart1520.f(new Building()));
        System.out.println(housePart1520.f(new House()));
    }
}

class Building {
}

class House extends Building {
}
